package com.ruoyi.mobile.utils;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.io.Serializable;

@Data
@ApiModel("统一结果封装")
public class NftResponse<T> implements Serializable {

    private static final long serialVersionUID = 2757435524710287976L;

    @ApiModelProperty(value = "响应消息")
    private String msg = "请求成功";

    @ApiModelProperty(value = "响应标识")
    private String code = "200";

    @ApiModelProperty(value = "响应内容")
    private T data;

    public NftResponse() {
    }

    public NftResponse(String code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public NftResponse(String code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public static NftResponse builderError(String msg) {
        return new NftResponse("500", msg, null);

    }

    public static <T> NftResponse<T> builderSuccess(T data) {
        return new NftResponse(ResultCode.SUCCESS.getCode(), "OK", data);
    }

    public static NftResponse builderSuccess() {
        return new NftResponse(ResultCode.SUCCESS.getCode(), "操作成功", null);
    }

    /**
     * 根据返回值来构建
     *
     * @param i
     * @return
     */
    public static NftResponse builder(int i) {
        if (i > 0) {
            return builderSuccess();
        }
        return builderError("操作失败");
    }

    /**
     * 根据返回值来构建
     *
     * @param flag
     * @return
     */
    public static NftResponse builder(boolean flag) {
        if (flag) {
            return builderSuccess();
        }
        return builderError("操作失败");
    }
}
